let express = require('express');
let app = express();

const bodyParser = require('body-parser');
app.use(bodyParser.json());//数据JSON类型
app.use(bodyParser.urlencoded({ extended: false }));//解析post请求数据

app.all('*', function (req, res, next) {
    let origin = req.headers.origin;
    res.setHeader('Access-Control-Allow-Origin', "*");
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    next();
})

// 登录
app.post('/login', function (req, res) {
    if (req.body.adminId && (req.body.adminId == req.body.password)) {
        console.log(req.body)
        res.json({ rtCode: "Y" });
    } else {
        res.json({ rtCode: "N" });
    }
})

// fund 数据
app.post('/fundInfo', function (req, res) {
    console.log(req.body.planetName)
    let info = [];
    for (let i = 0; i < 30; i++) {
        info[i] = {}
        info[i].year = 3000 + i
        info[i].revenue = Math.round(Math.random() * 20 * (i + 1) + 20 * (i + 1))
        info[i].expenditure = -(Math.round(Math.random() * 20 * (i + 1)))
        info[i].profit = info[i].revenue + info[i].expenditure
    }
    // switch (req.body.planetName) {
    //     case "Augstom":

    //         break;

    //     default:
    //         break;
    // }
    res.json({ planetInfo: info })
})



app.listen(8080);